﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AccessControl.Contracts.Settings;
using AccessControl.Contracts.Models;
using System.Collections.ObjectModel;
using AccessControl.DataManagers;

namespace AccessControl.Gateway.Settings
{
	class OperatorsSettings : IOperatorsSettings
	{
		#region Fields

		private static OperatorsSettings s_Instance = null;
		ObservableCollection<IOperator> _Items = new ObservableCollection<IOperator>();

		#endregion

		#region Private Constructor

		private OperatorsSettings()
		{
			DataManager.Instance.FillList(Items);
		}

		#endregion

		#region Public Properties

		public static OperatorsSettings Instance
		{
			get 
			{
				lock (typeof(OperatorsSettings))
				{
					if (s_Instance == null)
						s_Instance = new OperatorsSettings();

					return s_Instance;
				}
			}
		}

		#endregion
		
		#region IOperatorsSettings Members

		public bool Add(IOperator item)
		{
			return DataManager.Instance.Add(item);
		}

		public bool Update(IOperator item)
		{
			return DataManager.Instance.Update(item);
		}

		public bool Delete(IOperator item)
		{
			return DataManager.Instance.Delete(item);

		}

		public IList<IOperator> Items
		{
			get { return _Items; }
		}

		public void Load()
		{
			Items.Clear();
			DataManager.Instance.FillList(Items);
		}

		#endregion
	}
}
